<!DOCTYPE html>
<html lang="zh-Hans-CN">
    <head>
        <title>工厂模式实例-吃货店</title>
        <meta charset="utf-8" />
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <meta name="author" content="chen" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge, chrome=1" />
        <!--<link rel="stylesheet" type="css/text" media="screen and ( min-width: 1200px )" href="">-->
        <link rel="stylesheet" type="text/css" media="screen" href="" />
        <script defer="defer" src=""></script>
        <style>
            /*@import url("css/name.css") screen and ( min-width: 1200px );*/
        </style>
    </head>

    <body>
        <script>
            let Shop = (function() {
                let s = {
                    Steak() {
                        this.price = 30;
                        this.time = 20;
                    },
                    Grill() {
                        this.price = 20;
                        this.time = 15;
                    },
                    Noodles() {
                        this.price = 15;
                        this.time = 10;
                    },
                    Rice() {
                        this.price = 8;
                        this.time = 5;
                    },
                    Malatang() {
                        this.price = 25;
                        this.time = 15;
                    }
                };
                return class Shop {
                    constructor(w) {
                        this._name = w;
                        try {
                            s[w].call(this);
                        } catch (e) {
                            throw new Error("需要的餐点不提供");
                        }
                    }
                    done() {
                        console.log(
                            this._name +
                                "制作完成，价格" +
                                this.price +
                                "，耗时" +
                                this.time
                        );
                    }
                };
            })();

            //实例
            let a = new Shop("Noodles");
            let b = new Shop("Rice");
            let c = new Shop("Malatang");

            a.done();
            b.done();
            c.done();
        </script>
    </body>
</html>
